(function () {
    'use strict';
    var describe = BDD.describe, it = BDD.it, expect = BDD.expect;

    describe('in this browser', function () {
        describe('the WebGL program info log', function () {
            var canvas = document.createElement('canvas'),
                gl = canvas.getContext('experimental-webgl'),
                p = gl.createProgram();
            gl.linkProgram(p);

            if (BROWSER.correctlyCapturesProgramInfoLog()) {
                it('gets captured correctly', function () {
                    expect(gl.getProgramParameter(p, gl.LINK_STATUS)).to.equal(false);
                    expect(gl.getProgramInfoLog(p)).to.match(/missing.*shader/i);
                });
            } else {
                it('does not get captured correctly', function () {
                    expect(gl.getProgramParameter(p, gl.LINK_STATUS)).to.equal(false);
                    expect(gl.getProgramInfoLog(p)).to.equal('');
                });
            }
        });

        // Cannot verify BROWSER.supportsStyledConsoleLogging()
        //
        describe('it is', function () {
            if (BROWSER.isWebkit()) {
                it('a Webkit flavour (Chrome, ...)', function () {
                    expect(document.body.style.webkitAnimation).to.be.a('string');
                });
            } else {
                it('not a Webkit flavour (Chrome, ...)', function () {
                    expect(document.body.style.webkitAnimation).to.be.an('undefined');
                });
            }

            if (BROWSER.isMozilla()) {
                it('Mozilla (Firefox, ...)', function () {
                    expect(document.body.style.MozAnimation).to.be.a('string');
                });
            } else {
                it('not Mozilla (Firefox, ...)', function () {
                    expect(document.body.style.MozAnimation).to.be.an('undefined');
                });
            }

            if (BROWSER.isIe()) {
                it('Ie', function () {
                    expect(document.body.style.msAnimation).to.be.a('string');
                });
            } else {
                it('not Ie', function () {
                    expect(document.body.style.msAnimation).to.be.an('undefined');
                });
            }
        });

        describe('stacktraces', function () {
            it('can be captured', function () {
                expect(BROWSER.stackTrace()).to.match(/browser_tests.js/);
            });
            if (BROWSER.canCaptureCustomStackTraces()) {
                it('can be customized', function () {
                    expect(BROWSER.stackTrace(function (err, csf, lines) {
                        lines.push('---');
                    })).to.match(/(---\n)+/);
                });
                describe('when customized', function () {
                    it('does not include a browser.js stack frame', function () {
                        expect(BROWSER.stackTrace(function (err, csf, lines) {
                            expect(csf.file).to.be.a('string');
                            expect(csf.line).to.be.a('number');
                            expect(csf.fn).to.be.a('string');
                            lines.push(csf.file);
                        })).to.not.match(/browser.js/);
                    });
                    it('can be limited', function () {
                        expect(BROWSER.stackTrace(function (err, csf, lines) {
                            lines.push('one');
                            return true;
                        })).to.equal('one');
                    });
                });
            } else {
                it('cannot be customized', function () {
                    expect(BROWSER.stackTrace(function (err, csf, lines) {
                        lines.push('---');
                    })).to.not.match(/(---\n)+/);
                });
            }
        });
    });
}());
